/*
 * @(#)GSLoginAction.java
 * 
 * Project: BUS
 * 
 * Modify Information:
 * =============================================================================
 * Author           Date           Description 
 * ------------   ----------  -------------------------------------------------- 
 * Simonyi Peng     2006-2-7        建立
 * Jenny   Li       2006-3-4      修改getManufactureByOpt，去掉2个值，添加读取集中编码值
 *                                修改getSql中查询的SQL
 * Jenny   Li       2006-3-16     增加getManufInfoByConcentricityId         
 * Simonyi Peng     2006-3-17     修改getManufactureByOpt_，修改getSql，增加getSql_，
 *                                增加getManufactureByKeyword，getSqlForKeyword
 * Jenny   Li       2006-3-18    添加方法getManufactureOfLevel
 * Simonyi Peng     2006-3-18    添加方法getManufactureByUnitPrice，getSqlForKeywordInManufactureBrowse，getManufactureByKeywordForBrowse
 * Simonyi Peng     2006-3-20    添加方法getProviderInfoByconcentricityid
 * Tuthmos Liu      2008-06-02   修改下载EXCEL表方法
 * Tuthmos Liu      2008-06-16   获取图件号
 * Copyright Notice:
 * =============================================================================
 * Copyright (c) 2001-2006 Beijing HiTRUST Technology Co., Ltd. 1808 Room,
 * Science & Technology Building, No. 9 South Street, Zhong Guan Cun, Haidian
 * District, Beijing ,100081, China All rights reserved.
 * 
 * This software is the confidential and proprietary information of Beijing
 * HiTRUST Technology Co., Ltd. ("Confidential Information"). You shall not
 * disclose such Confidential Information and shall use it only in accordance
 * with the terms of the license agreement you entered into with HiTRUST.
 * 
 * Warning:
 * =============================================================================
 *  
 */
package com.hitrust.gs.business;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;

import com.hitrust.gs.bean.GSManufactureBean;
import com.hitrust.gs.bean.GSManufactureCategoryBean;
import com.hitrust.gs.bean.GSManufacturedBean;
import com.hitrust.gs.bean.GSOperatorBean;
import com.hitrust.gs.bean.GSOrderDetailBean;
import com.hitrust.gs.bean.GSProductStorageApepBean;
import com.hitrust.gs.bean.GSWareHouseBean;
import com.hitrust.gs.bean.GSWareHouseProductBean;
import com.hitrust.gs.dao.GSManufactureCategoryDAO;
import com.hitrust.gs.dao.GSManufactureDAO;
import com.hitrust.gs.dao.GSOperatorDAO;
import com.hitrust.gs.dao.GSProviderDAO;
import com.hitrust.gs.lib.GSAutoAuditongDateConfigurator;
import com.hitrust.gs.lib.GSBaseConstants;
import com.hitrust.gs.lib.GSLogWriter;
import com.hitrust.gs.lib.GSSystemConfigurator;
import com.hitrust.gs.service.GSBaseForm;
import com.hitrust.gs.service.GSBaseManager;
import com.hitrust.gs.service.GSBaseProcesser;
import com.hitrust.gs.util.DefineDic;
import com.hitrust.gs.util.GenRandNum;
import com.hitrust.gs.util.date.DateUtil;
import com.hitrust.gs.util.exception.GSException;
import com.hitrust.gs.util.lang.StringUtils;
import com.hitrust.gs.vo.GSManufactureVO;
import com.hitrust.gs.vo.GSOrderManufactureVO;
import com.hitrust.gs.vo.GSProviderSimpleWithManufVO;
import com.hitrust.gs.vo.GSProviderWithPriceVO;

public class GSManufactureProcessor implements GSBaseProcesser {

	GSManufactureDAO dao = new GSManufactureDAO();

	public void addManufactureIntoOrder(String orderCode, GSManufactureVO vo)
			throws GSException {

	}

	/**
	 * 根据集中编码查询价格最低的产品
	 */
	public GSManufactureBean getManufactureByUnitPrice(String concentricityId)
			throws GSException {
		return dao.getManufactureByUnitPrice(concentricityId);
	}

	/**
	 * 返回GSOrderDetailBean数组
	 * 
	 * @param orderCode
	 * @return
	 * @throws GSException
	 */
	public ArrayList selectManufactureByOrder(String orderCode)
			throws GSException {
		return null;
	}

	public GSOrderDetailBean selectManufactureByCode(String manufactureCode)
			throws GSException {
		return null;
	}

	public boolean saveManufacture(GSManufactureVO vo) throws GSException {
		boolean bl = dao.insert(vo);
		return bl;
	}

	public boolean saveManufactureKM(GSManufactureVO vo) throws GSException {
		boolean bl = dao.insertForKM(vo);
		return bl;
	}
	
	public boolean saveManufactureKM(GSManufactureVO vo,String providerid,String planprice) throws GSException {
		boolean bl = dao.insertForKM(vo,providerid,planprice);
		return bl;
	}

	public boolean deleteManufacture(GSManufactureVO vo) throws GSException {
		boolean bl = dao.deleteProduct(vo.getGs_concentricity_id());
		return bl;
	}

	public boolean modifyManufacture(GSManufactureVO vo) throws GSException {
		boolean bl = dao.update(vo);
		return bl;
	}

	public boolean modifyManufactureKM(GSManufactureVO vo) throws GSException {
		boolean bl = dao.updateForKM(vo);
		return bl;
	}

	public boolean modifyManufactureByCondition(GSManufactureVO vo)
			throws GSException {
		boolean bl = dao.updateByCondition(vo);
		return bl;
	}

	public boolean modifyManufactureByConditionKM(GSManufactureVO vo)
			throws GSException {
		boolean bl = dao.updateByConditionKM(vo);
		return bl;
	}
	
	public boolean modifyManufactureByConditionKM(GSManufactureVO vo,String providerid,String planprice)
	throws GSException {
		boolean bl = dao.updateByConditionKM(vo,providerid,planprice);
		return bl;
	}

	public boolean invalidationManufacture(GSManufactureVO vo)
			throws GSException {
		boolean bl = dao.invalidation(vo);
		return bl;
	}

	public ArrayList query(String sql) throws GSException {

		return null;
	}

	public void modifyOrderManufacture(GSOrderManufactureVO vo)
			throws GSException {

	}

	/**
	 * 用于订单输入页面的产品号检测
	 * 
	 * @param manufactureId
	 * @return
	 * @throws GSException
	 */
	public GSManufactureBean getManufactureForOrderInput(String value,
			ArrayList tempList) {
		GSManufactureBean tBean = null;
		try {
			// 先查 gs_Concentricity_Id
			tBean = dao.getManufactureByConcentricityId(value,
					this.getFilterView(tempList));

			if (tBean == null) {
				if (GSSystemConfigurator.getParam("gs.SetManufactureCode13")
						.equalsIgnoreCase("true")) {
					// 如果设定了使用13码方式则使用13码的查询方式,否则为原默认方式
					tBean = dao.getManufactureByIdBefore12(value,
							this.getFilterView(tempList));
				} else {
					// 如tBean==null,查gs_manufacture_id的前14位（巴士集中码)
					tBean = dao.getManufactureByIdBefore14(value,
							this.getFilterView(tempList));
				}
			}

		} catch (GSException e) {
		}

		return tBean;
	}

	/**
	 * 根据产品等级查询产品种类
	 * 
	 * @param aLevel
	 *            产品种类等级
	 * @return 产品种类对象
	 * @throws GSException
	 */
	public ArrayList getManufactureType(String aLevel) throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureCategoryDAO tGSManufactureDAO = new GSManufactureCategoryDAO();
		tList = tGSManufactureDAO.queryManufactureByLevel(aLevel);
		return tList;
	}

	/**
	 * 根据查询条件组合不同SQL查询产品信息
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public ArrayList getManufactureByOpt_(GSManufactureVO aGSManufactureVO,
			int pageNo, int pageSize) throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSqlByTemp(aGSManufactureVO);
		GSLogWriter.debug(this, tSql.toString());
		// 执行查询产品
		tList = tGSManufactureDAO.queryManufactureByOpt(tSql.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();
			GSProviderDAO pdao = new GSProviderDAO();
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[18];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period(); // 数量单位
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[13] = tGSManufacture.getGs_manufacture_category_id();
				tStr[14] = pdao.queryProvider(
						tGSManufacture.getGs_provider_id())
						.getGs_provider_shortname();// 供应商名称
				tStr[15] = tGSManufacture.getGs_balance_mode();
				tStr[16] = tGSManufacture.getGs_drawing_peice_code();
				tStr[17] = tGSManufacture.getProviderName();
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	// 新加方法，更改申购单时用
	public ArrayList getManufactureForModifyToBefore14(String aConcentricityId,
			ArrayList templist) throws GSException {
		GSManufactureDAO tGSManufactureDao = new GSManufactureDAO();
		String tSql = this.getFilterView(templist) + "  and APEP_CODE like '"
				+ aConcentricityId + "____'  order by CONCENTRICITY_CODE ";
		ArrayList tList = null;
		ArrayList returnValue = new ArrayList();
		try {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();

			tList = tGSManufactureDao.executeQuery(new GSManufactureBean(),
					tSql, null);
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[16];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period(); // 数量单位
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[15] = tGSManufacture.getGs_balance_mode();
				returnValue.add(tStr);
			}
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}
		return returnValue;
	}

	// 新加方法，采用13位编码方式更改申购单时用
	public ArrayList getManufactureForModifyToBefore12(String aConcentricityId,
			ArrayList templist) throws GSException {
		GSManufactureDAO tGSManufactureDao = new GSManufactureDAO();
		String strConcentricityId = aConcentricityId.trim();
		if (strConcentricityId.length() == 12) {
			strConcentricityId += "_";
		}
		String tSql = this.getFilterView(templist)
				+ "  and CONCENTRICITY_CODE like '" + strConcentricityId
				+ "' order by CONCENTRICITY_CODE ";
		ArrayList tList = null;
		ArrayList returnValue = new ArrayList();
		try {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();

			tList = tGSManufactureDao.executeQuery(new GSManufactureBean(),
					tSql, null);
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[16];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period(); // 数量单位
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[15] = tGSManufacture.getGs_balance_mode();
				returnValue.add(tStr);
			}
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}
		return returnValue;
	}

	public ArrayList getManufactureByOpt_WithProvider(
			GSManufactureVO aGSManufactureVO, int pageNo, int pageSize)
			throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSql_WithProvider(aGSManufactureVO);
		GSLogWriter.debug(this, tSql.toString());
		// 执行查询产品
		tList = tGSManufactureDAO.queryManufactureByOpt(tSql.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[13];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period(); // 数量单位
				tStr[12] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	/**
	 * 产品浏览，条件查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByOpt(GSManufactureVO aGSManufactureVO)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSql(aGSManufactureVO);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 订单录入，条件查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByOpt_(GSManufactureVO aGSManufactureVO)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSql_(aGSManufactureVO);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	public int getManufactureCountByOpt_WithProvider(
			GSManufactureVO aGSManufactureVO) throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSql_WithProvider(aGSManufactureVO);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 产品浏览，关键字查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByKeywordForBrowse(String keyword)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;
		// 取得查询SQL
		String tSql = this.getSqlForKeywordInManufactureBrowse(vo, keyword);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 产品浏览，关键字查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByKeywordForOther(String keyword,
			ArrayList tmplist) throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;
		vo.gsValidity = "1";
		vo.setTmplist(tmplist);
		// 取得查询SQL
		String tSql = this.getSqlForKeywordOther(vo, keyword);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 订单录入选择产品，关键字查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByKeyword(String keyword, ArrayList tmplist)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;
		// 取得查询SQL
		String tSql = this.getSqlForKeyword(vo, keyword, tmplist);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	public int getManufactureCountByKeywordWithProvider(String keyword,
			String providerId) throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;
		// 取得查询SQL
		String tSql = this
				.getSqlForKeywordWithProvider(vo, keyword, providerId);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 根据查询条件组合不同SQL查询产品信息
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public ArrayList getManufactureByOpt(GSManufactureVO aGSManufactureVO,
			int pageNo, int pageSize) throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSql(aGSManufactureVO);
		GSLogWriter.debug(this, tSql.toString());
		// 执行查询产品
		tList = tGSManufactureDAO.queryManufactureByOpt(tSql.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[14];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = Double.toString(tGSManufacture
						.getGs_manufacture_unitprice());// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getProviderName();
				tStr[13] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);

			}
		}
		return tRs;
	}

	/**
	 * 根据查询条件组合不同SQL查询产品信息
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public ArrayList getManufactureByOptForDownload(String sql)
			throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = sql;
		GSLogWriter.debug(this, tSql.toString());
		// 执行查询产品
		tList = tGSManufactureDAO.queryManufactureByOptd(tSql.toString());
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[17];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = Double.toString(tGSManufacture
						.getGs_manufacture_unitprice());// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getGs_make_area();// 产地
				tStr[13] = tGSManufacture.getProviderName();// 供应商
				tStr[14] = tGSManufacture.getGs_manufacture_category_desc();// 产品分类
				tStr[15] = tGSManufacture.getGs_drawing_peice_code();// 图件号
				tStr[16] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);

			}
		}
		return tRs;
	}

	/**
	 * 过滤语句，同时去除重复集中编码记录
	 * */
	private String getFilterView(ArrayList tmplist) {
		StringBuffer result = new StringBuffer();
		result.append("select * from T_PRODUCT_FILTER_VIEW where 1=1 ");
		if (tmplist != null && tmplist.size() > 0) {
			String tmp = "";
			for (int tI = 0; tI < tmplist.size(); tI++) {
				GSWareHouseBean houseBean = (GSWareHouseBean) tmplist.get(tI);
				tmp += "'" + houseBean.getCode() + "',";
			}
			result.append(" and WAREHOUSE_CODE in ("
					+ tmp.substring(0, tmp.length() - 1) + ")");
		}
		return result.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL,根据是否交易平台特约产品顺序查询产品 依据：特约平台产品为
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	private String getSql_(GSManufactureVO aGSManufactureVO) {
		StringBuffer aSql = new StringBuffer();
		aSql.append(this.getFilterView(aGSManufactureVO.getTmplist()));
		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and MANUFATURER like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}

		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and CONCENTRICITY_CODE like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and MODEL like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and PRODUCT_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {
				aSql.append(" and CATEGORY_CODE like '%'");
			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY e where CATEGORY_CODE = e.CODE and (e.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or e.CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY e where CATEGORY_CODE = e.CODE and (e.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or e.CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and CATEGORY_CODE like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}
		// 买断还是压库
		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and BALANCE_MODE like '%"
					+ aGSManufactureVO.gs_balance_mode + "%' ");
		}
		// 图件号
		if (aGSManufactureVO.drawingpiececode != null
				&& !aGSManufactureVO.drawingpiececode.equals("")) {
			aSql.append(" and DRAWING_PIECE_CODE like '%"
					+ aGSManufactureVO.drawingpiececode.trim() + "%'");
		}
		// 供应商
		if (aGSManufactureVO.provider_name != null
				&& !aGSManufactureVO.provider_name.equals("")) {
			aSql.append(" and PROVIDER_NAME like '%"
					+ aGSManufactureVO.provider_name.trim() + "%'");
		}
		aSql.append(" and is_buy='1' ");

		aSql.append(" order by CONCENTRICITY_CODE");
		return aSql.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL,根据是否交易平台特约产品顺序查询产品 依据：特约平台产品为,临时产品增加了判断
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	private String getSqlByTemp(GSManufactureVO aGSManufactureVO) {
		StringBuffer aSql = new StringBuffer();
		aSql.append(this.getFilterView(aGSManufactureVO.getTmplist()));
		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and MANUFATURER like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}

		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and CONCENTRICITY_CODE like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and MODEL like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and PRODUCT_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {
				aSql.append(" and CATEGORY_CODE like '%'");
			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY e where CATEGORY_CODE = e.CODE and (e.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or e.CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY e where CATEGORY_CODE = e.CODE and (e.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or e.CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and CATEGORY_CODE like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}
		// 买断还是压库
		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and BALANCE_MODE like '%"
					+ aGSManufactureVO.gs_balance_mode + "%' ");
		}
		// 图件号
		if (aGSManufactureVO.drawingpiececode != null
				&& !aGSManufactureVO.drawingpiececode.equals("")) {
			aSql.append(" and DRAWING_PIECE_CODE like '%"
					+ aGSManufactureVO.drawingpiececode.trim() + "%'");
		}
		// 供应商
		if (aGSManufactureVO.provider_name != null
				&& !aGSManufactureVO.provider_name.equals("")) {
			aSql.append(" and PROVIDER_NAME like '%"
					+ aGSManufactureVO.provider_name.trim() + "%'");
		}
		aSql.append(" and is_buy='1' ");
		String warehouseCode = aGSManufactureVO.warehouse_code;
		if (!warehouseCode.equals("00000400")
				&& !warehouseCode.equals("0000040000")
				&& !warehouseCode.equals("0000040001")) {
			aSql.append(" and length(concentricity_code) <=14 ");
		}

		aSql.append(" order by CONCENTRICITY_CODE");
		return aSql.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL,根据是否交易平台特约产品顺序查询产品 依据：特约平台产品为
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	private String getSql_WithProvider(GSManufactureVO aGSManufactureVO) {
		StringBuffer aSql = new StringBuffer();
		aSql.append("select m.* from (select * from GS_Manufacture_FILTER_VIEW a where 1=1 ");
		if (aGSManufactureVO.gs_provider_id != null
				&& !"".equals(aGSManufactureVO.gs_provider_id)) {
			aSql.append(" and a.gs_provider_id = '"
					+ aGSManufactureVO.gs_provider_id + "' ");
		}
		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and a.GS_MANUFACTURER_NAME like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}
		// 判断VO对象中产品编码是否存在
		// if(aGSManufactureVO.gs_manufacture_id != null &&
		// !aGSManufactureVO.gs_manufacture_id.equals("")){
		// aSql.append(" and a.GS_MANUFACTURE_ID like '%" +
		// aGSManufactureVO.gs_manufacture_id.trim() + "%'");
		// }

		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and a.GS_CONCENTRICITY_ID like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_TYPE like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {
				aSql.append(" and a.GS_MANUFACTURE_CATEGORY_ID like '%'");
			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select GS_MANUFACTURE_CATEGORY_ID from gs_manufacture_category c where a.GS_MANUFACTURE_CATEGORY_ID = c.GS_MANUFACTURE_CATEGORY_ID and (c.GS_MANUFACTURE_CATEGORY_ID = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or c.GS_MANUFACTURE_CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select GS_MANUFACTURE_CATEGORY_ID from gs_manufacture_category c where a.GS_MANUFACTURE_CATEGORY_ID = c.GS_MANUFACTURE_CATEGORY_ID and (c.GS_MANUFACTURE_CATEGORY_ID = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or c.GS_MANUFACTURE_CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and a.GS_MANUFACTURE_CATEGORY_ID like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}
		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and a.gs_balance_mode like '%"
					+ aGSManufactureVO.gs_balance_mode + "%' ");
		}
		aSql.append(" and a.is_buy='1') m ");
		// aSql.append(" ) m,");
		// aSql.append("(select GS_CONCENTRICITY_ID,MIN(GS_IS_TRADEFLAT_MANUFACTURE) GS_IS_TRADEFLAT_MANUFACTURE from gs_manufacture group by GS_CONCENTRICITY_ID) b ");
		// aSql.append(" where m.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID and m.GS_IS_TRADEFLAT_MANUFACTURE=b.GS_IS_TRADEFLAT_MANUFACTURE ");

		// 判断VO对象中产品最小单位价格是否存在
		// if(aGSManufactureVO.gs_manufacture_price_min != null &&
		// !aGSManufactureVO.gs_manufacture_price_min.equals("")){
		// if(aSql.toString().indexOf("where") != -1){
		// aSql.append(" and a.GS_MANUFACTURE_UNITPRICE >=" +
		// Double.parseDouble(aGSManufactureVO.gs_manufacture_price_min));
		// }else{
		// aSql.append(" where a.GS_MANUFACTURE_UNITPRICE >=" +
		// Double.parseDouble(aGSManufactureVO.gs_manufacture_price_min));
		// }
		// }
		// //判断VO对象中产品最大单位价格是否存在
		// if(aGSManufactureVO.gs_manufacture_price_max != null &&
		// !aGSManufactureVO.gs_manufacture_price_max.equals("")){
		// if(aSql.toString().indexOf("where") != -1){
		// aSql.append(" and a.GS_MANUFACTURE_UNITPRICE <=" +
		// Double.parseDouble(aGSManufactureVO.gs_manufacture_price_max));
		// }else{
		// aSql.append(" where a.GS_MANUFACTURE_UNITPRICE <=" +
		// Double.parseDouble(aGSManufactureVO.gs_manufacture_price_max));
		// }
		// }
		aSql.append(" order by m.GS_CONCENTRICITY_ID");
		return aSql.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	public String getSql(GSManufactureVO aGSManufactureVO) throws GSException {
		StringBuffer aSql = new StringBuffer();
		aSql.append("select a.*,p.gs_provider_shortname as providername,c.GS_MANUFACTURE_DESC from GS_Manufacture a,GS_PROVIDER p,Gs_Manufacture_Category c where  a.GS_VALIDITY ='1' and p.GS_VALIDITY ='1' and a.gs_provider_id = p.gs_provider_id and a.GS_MANUFACTURE_CATEGORY_ID=c.GS_MANUFACTURE_CATEGORY_ID ");
		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and a.GS_MANUFACTURER_NAME like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}
		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and a.GS_CONCENTRICITY_ID like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_TYPE like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and a.GS_MANUFACTURE_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中供应商简称是否存在
		if (aGSManufactureVO.gs_provider_short_name != null
				&& !aGSManufactureVO.gs_provider_short_name.equals("")) {
			aSql.append(" and p.GS_provider_shortname = '"
					+ aGSManufactureVO.gs_provider_short_name.trim() + "'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {
				aSql.append(" and a.GS_MANUFACTURE_CATEGORY_ID like '%'");
			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select GS_MANUFACTURE_CATEGORY_ID from gs_manufacture_category c where a.GS_MANUFACTURE_CATEGORY_ID = c.GS_MANUFACTURE_CATEGORY_ID and (c.GS_MANUFACTURE_CATEGORY_ID = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or c.GS_MANUFACTURE_CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select GS_MANUFACTURE_CATEGORY_ID from gs_manufacture_category c where a.GS_MANUFACTURE_CATEGORY_ID = c.GS_MANUFACTURE_CATEGORY_ID and (c.GS_MANUFACTURE_CATEGORY_ID = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or c.GS_MANUFACTURE_CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and a.GS_MANUFACTURE_CATEGORY_ID like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}
		// 判断VO对象中图件号是否存在
		if (aGSManufactureVO.gs_drawing_peice_code != null
				&& !aGSManufactureVO.gs_drawing_peice_code.equals("")) {
			aSql.append(" and a.GS_DRAWING_PIECE_CODE = '"
					+ aGSManufactureVO.gs_drawing_peice_code.trim() + "'");
		}
		// 判断VO对象中结算模式是否存在
		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and a.gs_balance_mode = '"
					+ aGSManufactureVO.gs_balance_mode.trim() + "' ");
		}
		aSql.append(" and a.is_buy='1' order by a.GS_CONCENTRICITY_ID");
		return aSql.toString();
	}

	/**
	 * 取得产品明细
	 * 
	 * @param aManufactureId
	 *            产品编码
	 * @return
	 * @throws GSException
	 */
	public GSManufactureBean getManufactureDetail(String aManufactureId)
			throws GSException {
		GSManufactureBean tGSManufacture = null;
		if (aManufactureId == null) {
			GSLogWriter.error(this, GSException.E10032_MSG);
			throw new GSException(GSException.E10032, GSException.E10032_MSG);
		}
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		tGSManufacture = tGSManufactureDAO.getManufacture(aManufactureId);
		if (tGSManufacture == null) {
			GSLogWriter.error(this, GSException.E10031_MSG);
			throw new GSException(GSException.E10031, GSException.E10031_MSG);
		}
		return tGSManufacture;

	}

	/**
	 * 取得产品明细
	 * 
	 * @param aManufactureId
	 *            产品编码
	 * @return
	 * @throws GSException
	 */
	public GSManufactureBean getManufactureDetailByConcentricityCode(
			String aManufactureId) throws GSException {
		GSManufactureBean tGSManufacture = null;
		if (aManufactureId == null) {
			GSLogWriter.error(this, GSException.E10032_MSG);
			throw new GSException(GSException.E10032, GSException.E10032_MSG);
		}
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		tGSManufacture = tGSManufactureDAO
				.getManufactureByConcentricityCode(aManufactureId);
		if (tGSManufacture == null) {
			GSLogWriter.error(this, GSException.E10031_MSG);
			throw new GSException(GSException.E10031, GSException.E10031_MSG);
		}
		return tGSManufacture;

	}

	public GSManufactureBean getManufactureDetailByGuId(String gId)
			throws GSException {
		GSManufactureBean tGSManufacture = null;
		if (gId == null) {
			GSLogWriter.error(this, GSException.E10032_MSG);
			throw new GSException(GSException.E10032, GSException.E10032_MSG);
		}
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		tGSManufacture = tGSManufactureDAO.getManufactureByGuId(gId);
		if (tGSManufacture == null) {
			GSLogWriter.error(this, GSException.E10031_MSG);
			throw new GSException(GSException.E10031, GSException.E10031_MSG);
		}
		return tGSManufacture;

	}

	/**
	 * 根据产品种类名称和产品编号查询产品
	 * 
	 * @return ArrayList
	 * @throws GSException
	 */

	public static ArrayList queryManageManufacture(String aManfactureId,
			String aCategoryId1, String aCategoryId2, String aCategoryId3)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		ArrayList tArrayList = new ArrayList();
		try {
			// 通过产品种类编号和产品种类名称所有产品种类
			tArrayList = tGSManufactureDAO.queryManufacture(aManfactureId,
					aCategoryId1, aCategoryId2, aCategoryId3);
		} catch (GSException e) {
			GSLogWriter.error("GSManufactureProcessor GSException: "
					+ e.toString());
		}
		return tArrayList;
	}

	/**
	 * 新增产品信息记录
	 * 
	 */
	public static void addTask(GSManufactureBean aGSManufactureBean)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// //判断供应商是否存在
		// if (tGSProviderDAO.isExist(aGSProviderBean.getGs_provider_id())) {
		// throw new GSException("该供应商已经存在");
		// }
		// 添加机构信息
		if (tGSManufactureDAO.add(aGSManufactureBean) == false) {
			throw new GSException("");
		}
	}

	/**
	 * 修改产品信息记录
	 * 
	 */
	public static void modifyTask(GSManufactureBean aGSManufactureBean)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// //判断供应商是否存在
		// if (tGSProviderDAO.isExist(aGSProviderBean.getGs_provider_id())) {
		// throw new GSException("该供应商已经存在");
		// }
		// 添加机构信息
		if (tGSManufactureDAO.modify(aGSManufactureBean) == false) {
			throw new GSException("");
		}
	}

	/**
	 * 修改产品信息记录
	 * 
	 */
	public boolean modifyTask2(GSManufactureVO vo) throws GSException {
		boolean bl = dao.modify2(vo);
		if (bl == false) {
			throw new GSException(GSException.E20042, GSException.E20042_MSG);
		}
		return bl;
	}

	/**
	 * 修改产品信息记录
	 * 
	 */
	public boolean modifyTask2KM(GSManufactureVO vo) throws GSException {
		boolean bl = dao.modify2KM(vo);
		if (bl == false) {
			throw new GSException(GSException.E20042, GSException.E20042_MSG);
		}
		return bl;
	}

	/**
	 * 修改产品isupdate状态
	 * 
	 */
	public boolean modifyIsUpdate(Connection con, String apep_code,
			String updateval) throws GSException {
		boolean bl = dao.modify(con, apep_code, updateval);
		if (bl == false) {
			throw new GSException(GSException.E20042, GSException.E20042_MSG);
		}
		return bl;
	}

	/**
	 * 删除产品信息
	 * 
	 * @param aManfactureId
	 *            机构编号
	 * 
	 *            throws GSException
	 */
	public static void withdrawTask(String aManfactureId) throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 删除产品信息
		if (tGSManufactureDAO.delete(aManfactureId) == false) {
			throw new GSException("");
		}
	}

	public ArrayList getManufactureByKeyword(String keyword, int pageNo,
			int pageSize, ArrayList tmplist) throws GSException {
		ArrayList tList = null;
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();

		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;

		String sqlbuf = this.getSqlForKeyword(vo, keyword, tmplist);
		tList = tGSManufactureDAO.queryManufactureByOpt(sqlbuf.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();
			GSProviderDAO pdao = new GSProviderDAO();
			for (int i = 0; i < tList.size(); i++) {

				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[18];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period();
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[13] = tGSManufacture.getGs_manufacture_category_id();
				tStr[14] = pdao.queryProvider(
						tGSManufacture.getGs_provider_id())
						.getGs_provider_shortname();// 供应商名称
				tStr[15] = tGSManufacture.getGs_balance_mode();
				tStr[16] = tGSManufacture.getGs_drawing_peice_code();
				tStr[17] = tGSManufacture.getProviderName();
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	public ArrayList getManufactureByKeywordWithProvider(String keyword,
			String providerId, int pageNo, int pageSize) throws GSException {
		ArrayList tList = null;
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();

		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;

		String sqlbuf = this.getSqlForKeywordWithProvider(vo, keyword,
				providerId);
		tList = tGSManufactureDAO.queryManufactureByOpt(sqlbuf.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			GSManufactureCategoryDAO tGSMcDAO = new GSManufactureCategoryDAO();
			for (int i = 0; i < tList.size(); i++) {

				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[13];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSMcDAO.queryManufactureCatetoryName(tGSManufacture
						.getGs_manufacture_category_id()); // 产品种类
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);
				tStr[11] = tGSManufacture.getGs_quality_assure_period();
				tStr[12] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	public ArrayList getManufactureByKeywordForBrowse(String sqlbuf,
			int pageNo, int pageSize) throws GSException {
		ArrayList tList = null;
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		tList = tGSManufactureDAO.queryManufactureByOpt(sqlbuf.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			for (int i = 0; i < tList.size(); i++) {

				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[14];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = Double.toString(tGSManufacture
						.getGs_manufacture_unitprice());// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getProviderName();
				tStr[13] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	public ArrayList getManufactureByKeywordForDownload(String sql)
			throws GSException {
		ArrayList tList = null;
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		tList = tGSManufactureDAO.queryManufactureByOptd(sql);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			for (int i = 0; i < tList.size(); i++) {

				GSManufacturedBean tGSManufacture = (GSManufacturedBean) tList
						.get(i);
				String[] tStr = new String[17];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = Double.toString(tGSManufacture
						.getGs_manufacture_unitprice());// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getGs_make_area();// 产地
				tStr[13] = tGSManufacture.getProviderName();// 供应商
				tStr[14] = tGSManufacture.getGs_manufacture_desc();// 产品分类
				tStr[15] = tGSManufacture.getGs_drawing_peice_code();// 图件号
				tStr[16] = tGSManufacture.getGs_balance_mode();// 结算模式
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	/**
	 * 根据条件组成不同的查询SQL
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	public String getSqlForKeywordInManufactureBrowse(
			GSManufactureVO aGSManufactureVO, String keyword)
			throws GSException {
		StringBuffer aSql = new StringBuffer();
		aSql.append("select a.*,p.gs_provider_shortname as Providername ,c.GS_MANUFACTURE_DESC from GS_Manufacture a,gs_provider p,Gs_Manufacture_Category c where a.GS_VALIDITY ='1' and p.GS_VALIDITY ='1' and a.gs_provider_id = p.gs_provider_id and a.GS_MANUFACTURE_CATEGORY_ID=c.GS_MANUFACTURE_CATEGORY_ID ");
		if (!keyword.equals("")) {
			aSql.append(" and (7<>7 ");

			// 判断VO对象中生产厂商是否存在
			if (aGSManufactureVO.gs_manufacturer_name != null
					&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
				aSql.append(" or a.GS_MANUFACTURER_NAME like '%"
						+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
			}

			// 判断VO对象中集中编码是否存在
			if (aGSManufactureVO.gs_concentricity_id != null
					&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
				aSql.append(" or a.GS_CONCENTRICITY_ID like '%"
						+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
			}
			// 判断VO对象中产品名称是否存在
			if (aGSManufactureVO.gs_manufacture_name != null
					&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_NAME like '%"
						+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
			}
			// 判断VO对象中产品规格是否存在
			if (aGSManufactureVO.gs_manufacture_spec != null
					&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_SPEC like '%"
						+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
			}
			// 判断VO对象中产品型号是否存在
			if (aGSManufactureVO.gs_manufacture_type != null
					&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_TYPE like '%"
						+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
			}
			// 判断VO对象中产品品牌是否存在
			if (aGSManufactureVO.gs_manufacture_brand != null
					&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_BRAND like '%"
						+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
			}
			// 判断VO对象中附件属性是否存在
			if (aGSManufactureVO.gs_appender_property != null
					&& !aGSManufactureVO.gs_appender_property.equals("")) {
				aSql.append(" or a.GS_APPENDER_PROPERTY like '%"
						+ aGSManufactureVO.gs_appender_property.trim() + "%'");
			}
		} else {
			aSql.append("and (1=1 ");
		}
		aSql.append(") order by a.GS_CONCENTRICITY_ID");
		return aSql.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	private String getSqlForKeyword(GSManufactureVO aGSManufactureVO,
			String keyword, ArrayList tmplist) throws GSException {
		StringBuffer aSql = new StringBuffer();
		aSql.append(this.getFilterView(tmplist));
		if (keyword != null && !"".equals(keyword)) {
			aSql.append(" and (1<>1 ");

			// 判断VO对象中生产厂商是否存在
			if (aGSManufactureVO.gs_manufacturer_name != null
					&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
				aSql.append(" or MANUFATURER like '%"
						+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
			}

			// 判断VO对象中集中编码是否存在
			if (aGSManufactureVO.gs_concentricity_id != null
					&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
				aSql.append(" or CONCENTRICITY_CODE like '%"
						+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
			}
			// 判断VO对象中产品名称是否存在
			if (aGSManufactureVO.gs_manufacture_name != null
					&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
				aSql.append(" or NAME like '%"
						+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
			}
			// 判断VO对象中产品规格是否存在
			if (aGSManufactureVO.gs_manufacture_spec != null
					&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
				aSql.append(" or SPEC like '%"
						+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
			}
			// 判断VO对象中产品型号是否存在
			if (aGSManufactureVO.gs_manufacture_type != null
					&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
				aSql.append(" or MODEL like '%"
						+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
			}
			// 判断VO对象中产品品牌是否存在
			if (aGSManufactureVO.gs_manufacture_brand != null
					&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
				aSql.append(" or PRODUCT_BRAND like '%"
						+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
			}
			// 判断VO对象中附件属性是否存在
			if (aGSManufactureVO.gs_appender_property != null
					&& !aGSManufactureVO.gs_appender_property.equals("")) {
				aSql.append(" or APPENDER_PROPERTY like '%"
						+ aGSManufactureVO.gs_appender_property.trim() + "%'");
			}
			aSql.append(")");
		} else {
			aSql.append(" and ( 1=1 )");
		}
		aSql.append(" order by CONCENTRICITY_CODE");
		return aSql.toString();
	}

	/**
	 * 根据条件组成不同的查询SQL
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	private String getSqlForKeywordWithProvider(
			GSManufactureVO aGSManufactureVO, String keyword, String providerId)
			throws GSException {
		StringBuffer aSql = new StringBuffer();
		aSql.append("select m.* from (select * from GS_Manufacture_filter_VIEW a where 1=1  ");
		if (providerId != null && !"".equals(providerId)) {
			aSql.append(" and a.gs_provider_id ='" + providerId + "' ");
		}
		if (!keyword.equals("")) {
			aSql.append(" and (7<>7 ");

			// 判断VO对象中生产厂商是否存在
			if (aGSManufactureVO.gs_manufacturer_name != null
					&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
				aSql.append(" or a.GS_MANUFACTURER_NAME like '%"
						+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
			}

			// 判断VO对象中集中编码是否存在
			if (aGSManufactureVO.gs_concentricity_id != null
					&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
				aSql.append(" or a.GS_CONCENTRICITY_ID like '%"
						+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
			}
			// 判断VO对象中产品名称是否存在
			if (aGSManufactureVO.gs_manufacture_name != null
					&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_NAME like '%"
						+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
			}
			// 判断VO对象中产品规格是否存在
			if (aGSManufactureVO.gs_manufacture_spec != null
					&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_SPEC like '%"
						+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
			}
			// 判断VO对象中产品型号是否存在
			if (aGSManufactureVO.gs_manufacture_type != null
					&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_TYPE like '%"
						+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
			}
			// 判断VO对象中产品品牌是否存在
			if (aGSManufactureVO.gs_manufacture_brand != null
					&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
				aSql.append(" or a.GS_MANUFACTURE_BRAND like '%"
						+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
			}
			// 判断VO对象中附件属性是否存在
			if (aGSManufactureVO.gs_appender_property != null
					&& !aGSManufactureVO.gs_appender_property.equals("")) {
				aSql.append(" or a.GS_APPENDER_PROPERTY like '%"
						+ aGSManufactureVO.gs_appender_property.trim() + "%'");
			}
			aSql.append(")");
		} else {
			aSql.append(" and ( 1=1 )");
		}

		aSql.append(") m ");
		// aSql.append(") m,");
		// aSql.append("(select GS_CONCENTRICITY_ID,MIN(GS_IS_TRADEFLAT_MANUFACTURE) GS_IS_TRADEFLAT_MANUFACTURE from gs_manufacture group by GS_CONCENTRICITY_ID) b ");
		// aSql.append(" where m.GS_CONCENTRICITY_ID=b.GS_CONCENTRICITY_ID and m.GS_IS_TRADEFLAT_MANUFACTURE=b.GS_IS_TRADEFLAT_MANUFACTURE ");

		aSql.append(" order by m.GS_CONCENTRICITY_ID");
		return aSql.toString();
	}

	/**
	 * 根据集中编码查询产品信息
	 * 
	 * @param aConcentricityId
	 *            集中编码
	 * @return
	 * @throws GSException
	 */
	public GSManufactureBean getManufInfoByConcentricityId(
			String aConcentricityId) throws GSException {
		GSManufactureBean tGSManufactureBean = null;
		GSManufactureDAO tManufDAO = new GSManufactureDAO();
		String tSql = "select * from t_product where CONCENTRICITY_CODE='"
				+ aConcentricityId + "'";
		ArrayList tList = tManufDAO.queryManufactureByOpt(tSql);
		if (tList.size() > 0) {
			// 取得任意一笔产品信息
			tGSManufactureBean = (GSManufactureBean) tList.get(0);
		}
		return tGSManufactureBean;
	}

	/**
	 * 根据apep编码查询产品信息
	 * 
	 * @param APEPCODE
	 * @return
	 * @throws GSException
	 */
	public GSManufactureBean getManufInfoByApepCode(String apepCode)
			throws GSException {
		GSManufactureBean tGSManufactureBean = null;
		GSManufactureDAO tManufDAO = new GSManufactureDAO();
		String tSql = "select * from t_product where APEP_CODE='" + apepCode
				+ "'";
		ArrayList tList = tManufDAO.queryManufactureByOpt(tSql);
		if (tList.size() > 0) {
			// 取得任意一笔产品信息
			tGSManufactureBean = (GSManufactureBean) tList.get(0);
		}
		return tGSManufactureBean;
	}

	/**
	 * 根据集中编码查询所有提供该集中编码的供应商
	 * 
	 * @param aConcentricityId
	 * @return
	 * @throws GSException
	 */
	public ArrayList getProviderInfoByconcentricityid(String aConcentricityId)
			throws GSException {
		GSProviderDAO tProvDAO = new GSProviderDAO();
		String tSql = "select P.*,M.APEP_CODE,M.UNIT_PRICE,M.IS_TRADEFLAT_PRODUCT,M.BALANCE_MODE from t_product M,t_provider P where CONCENTRICITY_CODE='"
				+ aConcentricityId
				+ "' and M.PROVIDER_CODE = P.code and M.status='1' and p.status='1'";
		ArrayList tList = null;
		try {
			tList = tProvDAO.executeQuery(new GSProviderWithPriceVO(), tSql,
					null);
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}
		return tList;
	}

	/**
	 * 根据供应商和集中编码查询产品编码
	 * 
	 * @param concentricityId
	 * @param providerId
	 * @return
	 * @throws GSException
	 */
	public String getManufactureIdByConcentricityIdAndProviderId(
			String concentricityId, String providerId) throws GSException {
		String sql = "select * from t_product where CONCENTRICITY_CODE like ? and PROVIDER_CODE = ?";

		String strConcentricityId = concentricityId.trim();
		if (GSSystemConfigurator.getParam("gs.SetManufactureCode13")
				.equalsIgnoreCase("true")) {
			if (strConcentricityId.length() == 12) {
				strConcentricityId += "_";
			}
		}

		GSManufactureDAO dao = new GSManufactureDAO();
		Object[] obj = new Object[] { strConcentricityId, providerId };
		String manufactureId = "";
		try {
			ArrayList ary = dao.executeQuery(new GSManufactureBean(), sql, obj);
			if (ary != null && ary.size() != 0) {
				manufactureId = ((GSManufactureBean) ary.get(0))
						.getGs_manufacture_id();
			}
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}
		return manufactureId;

	}

	/**
	 * 根据集中编码查询所有提供该集中编码的供应商
	 * 
	 * @param aConcentricityId
	 * @return
	 * @throws GSException
	 */
	public ArrayList getProviderSimpleByconcentricityid(
			String aConcentricityId, String wareCode) throws GSException {
		GSProviderDAO tProvDAO = new GSProviderDAO();
		// 1.先按GS_CONCENTRICITY_ID查

		String strConcentricityId = aConcentricityId.trim();
		String tSql = "";

		if (GSSystemConfigurator.getParam("gs.SetManufactureCode13")
				.equalsIgnoreCase("true")) {
			String unstr = "";
			for (int i = 0; i < GSBaseConstants.PRODUCT_CONCENTRICITY
					- GSBaseConstants.MANUFACTURE_CODE_LENGTH; i++) {
				unstr += "_";
			}
			if (strConcentricityId.length() == GSBaseConstants.MANUFACTURE_CODE_LENGTH) {
				strConcentricityId += unstr;
			}
			tSql = "select P.CODE,P.NAME,P.IS_TRADEFLAT_PROVIDER,M.CONCENTRICITY_CODE,M.APEP_CODE,M.UNIT_PRICE,M.IS_TRADEFLAT_PRODUCT,M.BALANCE_MODE,M.ID from T_PRODUCT M,T_PROVIDER P where m.CONCENTRICITY_CODE like '"
					+ strConcentricityId
					+ "' and M.PROVIDER_CODE = P.CODE and M.STATUS='1' and p.STATUS='1' and M.is_buy='1' order by M.unit_price";
		} else {
			// 原来的默认方式
			tSql = "select P.CODE,P.NAME,P.IS_TRADEFLAT_PROVIDER,M.CONCENTRICITY_CODE,M.APEP_CODE,M.UNIT_PRICE,M.IS_TRADEFLAT_PRODUCT,M.BALANCE_MODE,M.ID from T_PRODUCT M,T_PROVIDER P where m.CONCENTRICITY_CODE ='"
					+ strConcentricityId
					+ "' and M.PROVIDER_CODE = P.CODE and M.STATUS='1' and p.STATUS='1' and M.is_buy='1' order by M.unit_price";
		}

		ArrayList tList = null;
		ArrayList returnValue = new ArrayList();
		try {
			tList = tProvDAO.executeQuery(new GSProviderSimpleWithManufVO(),
					tSql, null);

			for (int i = 0; i < tList.size(); i++) {
				GSProviderSimpleWithManufVO bean = (GSProviderSimpleWithManufVO) tList
						.get(i);
				String[] str = new String[6];
				str[0] = bean.providerId;
				str[1] = bean.providerShortName;
				str[2] = bean.concentricityId;
				str[3] = bean.manufactureId;
				str[4] = StringUtils.formatEDouble(bean.unitPrice, 4);
				// 根据仓库编码及产品guid获取该仓库该产品结算模式如果为空采用产品结算模式
				GSWareHouseProductBean ware = this.getWareHouseProduct(
						wareCode, bean.id);
				if (ware == null) {
					str[5] = bean.balancemode;
				} else {
					str[5] = ware.getBalance_mode();
				}
				returnValue.add(str);
			}
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}

		if (tList == null || tList.size() == 0) {
			// 2.如按1查不到，则有如下处理
			if (GSSystemConfigurator.getParam("gs.SetManufactureCode13")
					.equalsIgnoreCase("true")) {
				// 如果采用了13位编码的方式，则按gs_concentricity_id的前12位来查
				strConcentricityId = aConcentricityId.trim();
				String unstr = "";
				for (int i = 0; i < GSBaseConstants.PRODUCT_CONCENTRICITY
						- GSBaseConstants.MANUFACTURE_CODE_LENGTH; i++) {
					unstr += "_";
				}
				if (strConcentricityId.length() == GSBaseConstants.MANUFACTURE_CODE_LENGTH) {
					strConcentricityId += unstr;
				}
				tSql = "select P.CODE,P.NAME,P.IS_TRADEFLAT_PROVIDER,M.CONCENTRICITY_CODE,M.APEP_CODE,M.UNIT_PRICE,M.IS_TRADEFLAT_PRODUCT,M.BALANCE_MODE,M.ID from T_PRODUCT M,T_PROVIDER P where m.CONCENTRICITY_CODE like '"
						+ strConcentricityId
						+ "' and M.PROVIDER_CODE = P.CODE and M.STATUS='1' and p.STATUS='1' and M.is_buy='1' order by M.unit_price";
			} else {
				// 原来默认的方式
				// 则按gs_manufacture_id的前14位来查
				tSql = "select P.CODE,P.NAME,P.IS_TRADEFLAT_PROVIDER,M.CONCENTRICITY_CODE,M.APEP_CODE,M.UNIT_PRICE,M.IS_TRADEFLAT_PRODUCT,M.BALANCE_MODE,M.ID from T_PRODUCT M,T_PROVIDER P where m.CONCENTRICITY_CODE like '"
						+ strConcentricityId
						+ "____' and M.PROVIDER_CODE = P.CODE and M.STATUS='1' and p.STATUS='1' and M.is_buy='1' order by M.unit_price";
			}
			try {
				tList = tProvDAO.executeQuery(
						new GSProviderSimpleWithManufVO(), tSql, null);

				for (int i = 0; i < tList.size(); i++) {
					GSProviderSimpleWithManufVO bean = (GSProviderSimpleWithManufVO) tList
							.get(i);
					String[] str = new String[5];
					str[0] = bean.providerId;
					str[1] = bean.providerShortName;
					str[2] = bean.concentricityId;
					str[3] = bean.manufactureId;
					str[4] = StringUtils.formatEDouble(bean.unitPrice, 4);
					// 根据仓库编码及产品guid获取该仓库该产品结算模式如果为空采用产品结算模式
					GSWareHouseProductBean ware = this.getWareHouseProduct(
							wareCode, bean.id);
					if (ware == null) {
						str[5] = bean.balancemode;
					} else {
						str[5] = ware.getBalance_mode();
					}
					returnValue.add(str);
				}
			} catch (Exception e) {
				throw new GSException(GSException.E00001,
						GSException.E00001_MSG);
			}
		}

		return returnValue;
	}

	/**
	 * 根据仓库编码及产品id获取warehoustProduct
	 * **/
	public GSWareHouseProductBean getWareHouseProduct(String wareCode,
			String produtId) throws Exception {
		String sql = "select * from T_WAREHOUSE_PRODUCT where WAREHOUSE_CODE=? and PRODUCT_ID=?";
		Object[] tobj = { wareCode, produtId };
		ArrayList tList = dao.executeQuery(new GSWareHouseProductBean(), sql,
				tobj);
		GSWareHouseProductBean bean = null;
		if (tList.size() > 0) {
			bean = (GSWareHouseProductBean) tList.get(0);
		}
		return bean;
	}

	public ArrayList getProviderSimpleByconcentricityidWithProvider(
			String aConcentricityId, String providerId) throws GSException {
		GSProviderDAO tProvDAO = new GSProviderDAO();

		String strConcentricityId = aConcentricityId.trim();
		String tSql = "";
		if (GSSystemConfigurator.getParam("gs.SetManufactureCode13")
				.equalsIgnoreCase("true")) {
			String unstr = "";
			for (int i = 0; i < GSBaseConstants.PRODUCT_CONCENTRICITY
					- GSBaseConstants.MANUFACTURE_CODE_LENGTH; i++) {
				unstr += "_";
			}
			if (strConcentricityId.length() == GSBaseConstants.MANUFACTURE_CODE_LENGTH) {
				strConcentricityId += unstr;
			}
			tSql = "select P.gs_provider_id,P.gs_provider_shortname,P.gs_is_tradeflat_provider,M.gs_concentricity_id,M.gs_manufacture_id,M.gs_manufacture_unitprice,M.gs_is_tradeflat_manufacture,M.gs_balance_mode from GS_MANUFACTURE M,GS_PROVIDER P where GS_CONCENTRICITY_ID like '"
					+ strConcentricityId
					+ "' and M.GS_PROVIDER_ID = P.GS_PROVIDER_ID and M.gs_provider_id = '"
					+ providerId + "'";
		} else {
			// 原来默认方式
			tSql = "select P.gs_provider_id,P.gs_provider_shortname,P.gs_is_tradeflat_provider,M.gs_concentricity_id,M.gs_manufacture_id,M.gs_manufacture_unitprice,M.gs_is_tradeflat_manufacture,M.gs_balance_mode from GS_MANUFACTURE M,GS_PROVIDER P where GS_CONCENTRICITY_ID = '"
					+ strConcentricityId
					+ "' and M.GS_PROVIDER_ID = P.GS_PROVIDER_ID and M.gs_provider_id = '"
					+ providerId + "'";
		}

		ArrayList tList = null;
		ArrayList returnValue = new ArrayList();
		try {
			tList = tProvDAO.executeQuery(new GSProviderSimpleWithManufVO(),
					tSql, null);

			for (int i = 0; i < tList.size(); i++) {
				GSProviderSimpleWithManufVO bean = (GSProviderSimpleWithManufVO) tList
						.get(i);
				String[] str = new String[6];
				str[0] = bean.providerId;
				str[1] = bean.providerShortName;
				str[2] = bean.concentricityId;
				str[3] = bean.manufactureId;
				str[4] = StringUtils.formatEDouble(bean.unitPrice, 4);
				str[5] = bean.balancemode;
				returnValue.add(str);
			}
		} catch (Exception e) {
			throw new GSException(GSException.E00001, GSException.E00001_MSG);
		}
		return returnValue;
	}

	/**
	 * 封装产品分类
	 * 
	 * @param aForm
	 *            基类FORM
	 * @throws GSException
	 */
	public void getManufactureOfLevel(GSBaseForm aForm) throws GSException {
		// 取得产品等级为1级的产品种类
		ArrayList tManuf1 = this.getManufactureType("1");
		aForm.getRequest().setAttribute("manufacture1", tManuf1);
		// 取得产品等级为2级的产品种类
		ArrayList tManuf2 = this.getManufactureType("2");
		// 取得产品等级为3级的产品种类
		ArrayList tManuf3 = this.getManufactureType("3");
		// 将每一级产品种类下一级产品种类取出组成ArrayList并放入HASHMAP中建立对应关系
		HashMap tMap1 = new HashMap();
		HashMap tMap2 = new HashMap();
		if (tManuf1 != null) {
			for (int i = 0; i < tManuf1.size(); i++) {
				// 一级产品种类
				GSManufactureCategoryBean tGSManufCategyBean = (GSManufactureCategoryBean) tManuf1
						.get(i);
				if (tManuf2 != null) {
					ArrayList tList1 = new ArrayList();
					for (int j = 0; j < tManuf2.size(); j++) {
						// 二级产品种类
						GSManufactureCategoryBean tGSManufactureBean1 = (GSManufactureCategoryBean) tManuf2
								.get(j);
						if (tGSManufCategyBean.getGs_manufacture_category_id()
								.equals(tGSManufactureBean1
										.getGs_manufacture_category_id1())) {
							tList1.add(tGSManufactureBean1);
						}
						ArrayList tList2 = new ArrayList();
						for (int k = 0; k < tManuf3.size(); k++) {
							// 三级产品种类
							GSManufactureCategoryBean tGSManufactureBean2 = (GSManufactureCategoryBean) tManuf3
									.get(k);
							if (tGSManufactureBean1
									.getGs_manufacture_category_id()
									.equals(tGSManufactureBean2
											.getGs_manufacture_category_id2())) {
								tList2.add(tGSManufactureBean2);
							}
						}
						if (tList2.size() > 0)
							tMap2.put(
									""
											+ tGSManufactureBean1
													.getGs_manufacture_category_id(),
									tList2);
					}
					if (tList1.size() > 0)
						tMap1.put(
								""
										+ tGSManufCategyBean
												.getGs_manufacture_category_id(),
								tList1);
				}
			}
		}
		aForm.getRequest().setAttribute("manufacturetyp2", tMap1);
		aForm.getRequest().setAttribute("manufacturetyp3", tMap2);
	}

	/**
	 * 根据查询条件组合不同SQL查询产品管理中信息
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public ArrayList getManufactureByData(GSManufactureVO aGSManufactureVO,
			int pageNo, int pageSize,String tableName) throws GSException {
		ArrayList tList = new ArrayList();
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		boolean flag = false;
		String tSql = this.getSqlDataForProductManage(aGSManufactureVO,tableName);
		GSLogWriter.debug(this, tSql.toString());
		// 执行查询产品

		tList = tGSManufactureDAO.queryManufactureByOpt(tSql.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			for (int i = 0; i < tList.size(); i++) {
				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				String[] tStr = new String[28];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[13] = tGSManufacture.getGs_is_tradeflat_manufacture();
				tStr[14] = tGSManufacture.getGs_provider_id();
				tStr[15] = GSBaseManager.getProviderShortName(tGSManufacture
						.getGs_provider_id());
				tStr[16] = GSBaseManager.getProviderTradeflat(tGSManufacture
						.getGs_provider_id());
				tStr[17] = tGSManufacture.getGs_drawing_peice_code();
				tStr[18] = tGSManufacture.getIs_buy();
				tStr[19] = tGSManufacture.getGs_validity();
				tStr[20] = tGSManufacture.getGs_manufacture_record_date();
				tStr[21] = DefineDic.getBalanceMode(tGSManufacture
						.getGs_balance_mode());
				tStr[22] = tGSManufacture.getIs_normal();
				tStr[23] = tGSManufacture.getWarehouse_code();
				tStr[24] = tGSManufacture.getWarehouse_name();
				tStr[25] = StringUtils.formatEDouble(
						tGSManufacture.getPlan_price(), 2);// 计划价
				tStr[26] = tGSManufacture.getKm_quality_assure_period();// 公里质保
				tStr[27] = tGSManufacture.getBalance_customer_code()==null?"0": tGSManufacture.getBalance_customer_code();// 是否到单车
				tRs.add(tStr);

			}
		}
		return tRs;
	}

	/**
	 * 根据条件组成不同的查询SQL产品管理中信息
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	public String getSqlData(GSManufactureVO aGSManufactureVO)
			throws GSException {
		StringBuffer aSql = new StringBuffer();

		aSql.append("select a.*,b.name provider_name from T_PRODUCT a, T_PROVIDER b");
		aSql.append(" where a.PROVIDER_CODE = b.CODE ");
		aSql.append(" and to_char(to_date(a.RECORD_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') >='"
				+ aGSManufactureVO.manufactureRecordDateStr + "'");
		aSql.append(" and to_char(to_date(a.RECORD_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <='"
				+ aGSManufactureVO.manufactureRecordDateEnd + "'");

		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and a.MANUFATURER like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}

		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and a.CONCENTRICITY_CODE like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and a.NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and a.SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and a.MODEL like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and a.PRODUCT_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中产品供应商是否存在
		if (aGSManufactureVO.gs_provider_short_name != null
				&& !aGSManufactureVO.gs_provider_short_name.equals("")) {
			aSql.append(" and b.NAME like '%"
					+ aGSManufactureVO.gs_provider_short_name.trim() + "%'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {
				aSql.append(" and a.CATEGORY_CODE like '%'");
			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY c where a.CATEGORY_CODE = c.CODE and (c.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or c.CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY c where a.CATEGORY_CODE = c.CODE and (c.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or c.CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and a.CATEGORY_CODE like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}

		// 是否正式产品
		if (aGSManufactureVO.gs_is_tradeflat_manufacture != null
				&& !aGSManufactureVO.gs_is_tradeflat_manufacture.equals("")) {
			// 判断是否是14位临时产品
			if (aGSManufactureVO.gs_is_tradeflat_manufacture.equals("2")) {
				aSql.append(" and length(a.CONCENTRICITY_CODE)=14  and IS_NORMAL like '%0%' ");
			} else
				aSql.append(" and IS_NORMAL like '%"
						+ aGSManufactureVO.gs_is_tradeflat_manufacture + "%'");

		}
		// 是否正式产品
		// if(aGSManufactureVO.is_normal != null &&
		// !aGSManufactureVO.is_normal.equals("")){
		// aSql.append(" and IS_NORMAL like '%" + aGSManufactureVO.is_normal +
		// "%'");
		// }
		if (aGSManufactureVO.gs_drawing_peice_code != null
				&& !aGSManufactureVO.gs_drawing_peice_code.equals("")) {
			aSql.append(" and a.DRAWING_PIECE_CODE like '%"
					+ aGSManufactureVO.gs_drawing_peice_code + "%'");
		}
		// 判断VO对象中是否采购是否存在
		if (aGSManufactureVO.is_buy != null
				&& !aGSManufactureVO.is_buy.equals("")) {
			aSql.append(" and a.IS_BUY like '%" + aGSManufactureVO.is_buy
					+ "%'");
		}

		if (aGSManufactureVO.gsValidity != null
				&& !aGSManufactureVO.gsValidity.equals("")) {
			aSql.append(" and a.STATUS like '%" + aGSManufactureVO.gsValidity
					+ "%'");
		}

		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and a.BALANCE_MODE like '%"
					+ aGSManufactureVO.gs_balance_mode + "%'");
		}
		if (aGSManufactureVO.provider_status != null
				&& !aGSManufactureVO.provider_status.equals("")) {
			aSql.append(" and b.STATUS like '%"
					+ aGSManufactureVO.provider_status + "%'");
		}
		if (aGSManufactureVO.warehousecode != null
				&& !"".equals(aGSManufactureVO.warehousecode)) {
			aSql.append(" and a.WAREHOUSE_CODE like '"
					+ aGSManufactureVO.warehousecode + "%'");
		} else if (aGSManufactureVO.getTmplist().size() > 0) {
			String tmp = "";
			for (int tI = 0; tI < aGSManufactureVO.getTmplist().size(); tI++) {
				GSWareHouseBean houseBean = (GSWareHouseBean) aGSManufactureVO
						.getTmplist().get(tI);
				tmp += "'" + houseBean.getCode() + "',";
			}
			aSql.append(" and a.WAREHOUSE_CODE in ("
					+ tmp.substring(0, tmp.length() - 1) + ")");
		}
		// if(aGSManufactureVO.productType!=null&&
		// !"".equals(aGSManufactureVO.productType)){
		// aSql.append(" and exists (select id from t_product_type where t_product_type.product_id = a.id and t_product_type.status='1' and t_product_type.PRODUCT_TYPE = "+aGSManufactureVO.productType+") ");
		// }
		String upperType = aGSManufactureVO.getUpperType() == null ? ""
				: aGSManufactureVO.getUpperType();// 区域分类
		String productType = aGSManufactureVO.getProductType() == null ? ""
				: aGSManufactureVO.getProductType();// 招标分类

		if (!upperType.equals("")) {
			aSql.append(" and a.id in (select product_id from t_product_type where status='1' and  product_type="
					+ upperType + ") ");
		}
		if (!productType.equals("")) {
			aSql.append(" and a.id in (select product_id from t_product_bid where status='1' and product_type="
					+ productType + ") ");
		}

		aSql.append(" order by a.RECORD_DATE DESC"); // a.GS_CONCENTRICITY_ID
		return aSql.toString();
	}
	
	
	
	
	 public String initDataForArea(String type) throws GSException {
		 	String tableName="";
		 	tableName="t_pro_"+DateUtil.getCurrentTime("DT", "AD")+"_"+GenRandNum.genRandNum(4);
	        String sql = "create table " + tableName+ " as select a.* from t_product a where a.id in (select product_id from t_product_type where status='1' and product_type="
					+ type + " ) ";
	        
	        GSOperatorDAO dao = new GSOperatorDAO();
	        Connection conn = null;
	        try{
	            conn = dao.getConnetion();
	            PreparedStatement pstmt1 = conn.prepareStatement(sql);
	            pstmt1.execute(sql);
	            pstmt1.close();
	           
	            conn.commit();
	            
	            return tableName;
	        }catch(Exception ex){
	            try{
	               
	            }catch(Exception e1){}
	            throw new GSException(GSException.E17791,GSException.E17791_MSG);
	        }finally{
	            try{
	     
	            }catch(Exception e2){}
	            GSOperatorDAO.close(conn);
	        }
	    }    
	 
	 public void dropTableForArea(String tableName) throws GSException {
	        String sql = "drop table " + tableName;
					
	        GSOperatorDAO dao = new GSOperatorDAO();
	        Connection conn = null;
	        try{
	            conn = dao.getConnetion();
	            PreparedStatement pstmt1 = conn.prepareStatement(sql);
	            pstmt1.executeUpdate(sql);
	            pstmt1.close();
	           
	            conn.commit();
	        }catch(Exception ex){
	            try{
	               
	            }catch(Exception e1){}
	            throw new GSException(GSException.E17791,GSException.E17791_MSG);
	        }finally{
	            try{
	     
	            }catch(Exception e2){}
	            GSOperatorDAO.close(conn);
	        }
	    }    
	/**
	 * 根据条件组成不同的查询SQL产品管理中信息
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	public String getSqlDataForProductManage(GSManufactureVO aGSManufactureVO,String tableName)
			throws GSException {
		StringBuffer aSql = new StringBuffer();
		
		String upperType = aGSManufactureVO.getUpperType() == null ? ""
				: aGSManufactureVO.getUpperType();// 区域分类
		if (!upperType.equals("")) {
			aSql.append("select a.*,b.name provider_name from " +tableName +" a, T_PROVIDER b");
		}else{
			aSql.append("select a.*,b.name provider_name from T_PRODUCT a, T_PROVIDER b");
		}
		
		aSql.append(" where a.PROVIDER_CODE = b.CODE ");
		if (!aGSManufactureVO.manufactureRecordDateStr.equals("00000000")) {
			aSql.append(" and to_char(to_date(a.RECORD_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') >='"
					+ aGSManufactureVO.manufactureRecordDateStr + "'");
		}
		if (!aGSManufactureVO.manufactureRecordDateEnd.equals("99999999")) {
			aSql.append(" and to_char(to_date(a.RECORD_DATE,'YYYY-MM-DD HH24:mi:ss'),'YYYYMMDD') <='"
					+ aGSManufactureVO.manufactureRecordDateEnd + "'");
		}
		// 判断VO对象中生产厂商是否存在
		if (aGSManufactureVO.gs_manufacturer_name != null
				&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
			aSql.append(" and a.MANUFATURER like '%"
					+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
		}

		// 判断VO对象中集中编码是否存在
		if (aGSManufactureVO.gs_concentricity_id != null
				&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
			aSql.append(" and a.CONCENTRICITY_CODE like '%"
					+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
		}
		// 判断VO对象中产品名称是否存在
		if (aGSManufactureVO.gs_manufacture_name != null
				&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
			aSql.append(" and a.NAME like '%"
					+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
		}
		// 判断VO对象中产品规格是否存在
		if (aGSManufactureVO.gs_manufacture_spec != null
				&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
			aSql.append(" and a.SPEC like '%"
					+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
		}
		// 判断VO对象中产品型号是否存在
		if (aGSManufactureVO.gs_manufacture_type != null
				&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
			aSql.append(" and a.MODEL like '%"
					+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
		}
		// 判断VO对象中产品品牌是否存在
		if (aGSManufactureVO.gs_manufacture_brand != null
				&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
			aSql.append(" and a.PRODUCT_BRAND like '%"
					+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
		}
		// 判断VO对象中产品供应商是否存在
		if (aGSManufactureVO.gs_provider_short_name != null
				&& !aGSManufactureVO.gs_provider_short_name.equals("")) {
			aSql.append(" and b.NAME like '%"
					+ aGSManufactureVO.gs_provider_short_name.trim() + "%'");
		}
		// 判断VO对象中产品种类是否存在
		if (aGSManufactureVO.gs_manufacture_category1 != null) {
			if (aGSManufactureVO.gs_manufacture_category1.equals("0")) {

			} else if (aGSManufactureVO.gs_manufacture_category2.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY c where a.CATEGORY_CODE = c.CODE and (c.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category1
						+ "' or c.CATEGORY_ID1= '"
						+ aGSManufactureVO.gs_manufacture_category1 + "'))");
			} else if (aGSManufactureVO.gs_manufacture_category3.equals("0")) {
				aSql.append(" and exists (select CODE from T_PRODUCT_CATEGORY c where a.CATEGORY_CODE = c.CODE and (c.CODE = '"
						+ aGSManufactureVO.gs_manufacture_category2
						+ "' or c.CATEGORY_ID2= '"
						+ aGSManufactureVO.gs_manufacture_category2 + "'))");
			} else {
				aSql.append(" and a.CATEGORY_CODE like '%"
						+ aGSManufactureVO.gs_manufacture_category3 + "%'");
			}
		}

		// 是否正式产品
		if (aGSManufactureVO.gs_is_tradeflat_manufacture != null
				&& !aGSManufactureVO.gs_is_tradeflat_manufacture.equals("")) {
			// 判断是否是14位临时产品
			if (aGSManufactureVO.gs_is_tradeflat_manufacture.equals("2")) {
				aSql.append(" and length(a.CONCENTRICITY_CODE)=14  and IS_NORMAL like '%0%' ");
			} else
				aSql.append(" and IS_NORMAL like '%"
						+ aGSManufactureVO.gs_is_tradeflat_manufacture + "%'");

		}
		// 是否正式产品
		// if(aGSManufactureVO.is_normal != null &&
		// !aGSManufactureVO.is_normal.equals("")){
		// aSql.append(" and IS_NORMAL like '%" + aGSManufactureVO.is_normal +
		// "%'");
		// }
		if (aGSManufactureVO.gs_drawing_peice_code != null
				&& !aGSManufactureVO.gs_drawing_peice_code.equals("")) {
			aSql.append(" and a.DRAWING_PIECE_CODE like '%"
					+ aGSManufactureVO.gs_drawing_peice_code + "%'");
		}
		// 判断VO对象中是否采购是否存在
		if (aGSManufactureVO.is_buy != null
				&& !aGSManufactureVO.is_buy.equals("")) {
			aSql.append(" and a.IS_BUY =" + aGSManufactureVO.is_buy);
		}
		// 判断VO对象中是否压库不可采购可以出库是否存在
		if (aGSManufactureVO.is_ykck != null
				&& !aGSManufactureVO.is_ykck.equals("")) {
			if(aGSManufactureVO.is_ykck.equals("1")){
				aSql.append(" and a.pic ='" + aGSManufactureVO.is_ykck+"'");
			}else{
				aSql.append(" and a.pic <>'1'");
			}
			
		}
		if (aGSManufactureVO.gsValidity != null
				&& !aGSManufactureVO.gsValidity.equals("")) {
			aSql.append(" and a.STATUS=" + aGSManufactureVO.gsValidity);
		}

		if (aGSManufactureVO.gs_balance_mode != null
				&& !aGSManufactureVO.gs_balance_mode.equals("")) {
			aSql.append(" and a.BALANCE_MODE="+aGSManufactureVO.gs_balance_mode);
		}
		if (aGSManufactureVO.provider_status != null
				&& !aGSManufactureVO.provider_status.equals("")) {
			aSql.append(" and b.STATUS="+aGSManufactureVO.provider_status);
		}
		if (aGSManufactureVO.warehousecode != null
				&& !"".equals(aGSManufactureVO.warehousecode)) {
			aSql.append(" and a.WAREHOUSE_CODE like '"
					+ aGSManufactureVO.warehousecode + "%'");
		}
		String isPic= aGSManufactureVO.getIs_pic()==null?"":aGSManufactureVO.getIs_pic();
		
		if("1".equals(isPic)){
			aSql.append(" and a.CONCENTRICITY_CODE in (select CONCENTRICITY_CODE from t_product_picture)" );
		}else if("0".equals(isPic)){
			aSql.append(" and a.CONCENTRICITY_CODE not in (select CONCENTRICITY_CODE from t_product_picture)");
		}
		String productType = aGSManufactureVO.getProductType() == null ? ""
				: aGSManufactureVO.getProductType();// 招标分类

	
		if (!productType.equals("")) {
			aSql.append(" and a.id in (select product_id from t_product_bid where status='1' and product_type="
					+ productType + ") ");
		}

		aSql.append(" order by a.RECORD_DATE DESC"); // a.GS_CONCENTRICITY_ID
		return aSql.toString();
	}

	/**
	 * 对产品名称、型号、规格、品牌、生产厂商、附加属性等六个关键字的模糊查询
	 * 
	 * @param keyword
	 * @param pageNo
	 * @param pageSize
	 * @return
	 * @throws GSException
	 */
	public ArrayList getManufactureByKeywordForOther(String keyword,
			ArrayList tmplist, int pageNo, int pageSize) throws GSException {
		ArrayList tList = null;
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();

		GSManufactureVO vo = new GSManufactureVO();
		vo.gs_manufacture_brand = keyword;
		vo.gs_manufacture_name = keyword;
		vo.gs_manufacture_spec = keyword;
		vo.gs_manufacture_type = keyword;
		vo.gs_manufacturer_name = keyword;
		vo.gs_appender_property = keyword;
		vo.gsValidity = "1";
		vo.setTmplist(tmplist);

		String sqlbuf = this.getSqlForKeywordOther(vo, keyword);
		tList = tGSManufactureDAO.queryManufactureByOpt(sqlbuf.toString(),
				pageNo, pageSize);
		// 查询结果封装
		ArrayList tRs = new ArrayList();
		if (tList.size() > 0) {
			String lastConcentricityId = "";
			for (int i = 0; i < tList.size(); i++) {

				GSManufactureBean tGSManufacture = (GSManufactureBean) tList
						.get(i);
				if (lastConcentricityId.equals(tGSManufacture
						.getGs_concentricity()))
					continue;
				lastConcentricityId = tGSManufacture.getGs_concentricity();
				String[] tStr = new String[27];
				tStr[0] = tGSManufacture.getGs_manufacture_id();
				tStr[1] = tGSManufacture.getGs_concentricity();
				tStr[2] = tGSManufacture.getGs_manufacture_name();
				tStr[3] = tGSManufacture.getGs_manufacturer_name();
				tStr[4] = tGSManufacture.getGs_manufacture_brand();
				tStr[5] = tGSManufacture.getGs_manufacturer_name();
				tStr[6] = tGSManufacture.getGs_manufacture_type();// 产品型号
				tStr[7] = tGSManufacture.getGs_manufacture_spec();// 产品规格
				tStr[8] = tGSManufacture.getGs_manufacture_images();
				tStr[9] = tGSManufacture.getGs_quant_unit(); // 数量单位
				tStr[10] = StringUtils.formatEDouble(
						tGSManufacture.getGs_manufacture_unitprice(), 4);// 单价
				tStr[11] = tGSManufacture.getGs_quality_assure_period();// 质保期
				tStr[12] = tGSManufacture.getGs_provider_id();
				tStr[13] = tGSManufacture.getGs_is_tradeflat_manufacture();
				tStr[14] = tGSManufacture.getGs_provider_id();
				tStr[15] = GSBaseManager.getProviderShortName(tGSManufacture
						.getGs_provider_id());
				tStr[16] = GSBaseManager.getProviderTradeflat(tGSManufacture
						.getGs_provider_id());
				tStr[17] = tGSManufacture.getGs_drawing_peice_code();
				tStr[18] = tGSManufacture.getIs_buy();
				tStr[19] = tGSManufacture.getGs_validity();
				tStr[20] = tGSManufacture.getGs_manufacture_record_date();
				tStr[21] = DefineDic.getBalanceMode(tGSManufacture
						.getGs_balance_mode());
				tStr[22] = tGSManufacture.getIs_normal();
				tStr[23] = tGSManufacture.getWarehouse_code();
				tStr[24] = tGSManufacture.getWarehouse_name();
				tStr[25] = StringUtils.formatEDouble(
						tGSManufacture.getPlan_price(), 2);// 计划价
				tStr[26] = tGSManufacture.getKm_quality_assure_period();// 公里质保
				tRs.add(tStr);
			}
		}
		return tRs;
	}

	/**
	 * 根据条件组成不同的查询SQL
	 * 
	 * @param aGSManufactureVO
	 *            VO对象
	 * @param aSql
	 *            查询SQL缓存
	 * @throws GSException
	 */
	public String getSqlForKeywordOther(GSManufactureVO aGSManufactureVO,
			String keyword) throws GSException {
		StringBuffer aSql = new StringBuffer();
		aSql.append("select a.* from T_PRODUCT a");
		aSql.append(" where a.APEP_CODE like '%'");
		if (aGSManufactureVO.gsValidity != null
				&& !"".equals(aGSManufactureVO.gsValidity)) {
			aSql.append(" and a.status='" + aGSManufactureVO.gsValidity + "'");
		}
		if (!keyword.equals("")) {
			aSql.append(" and (7<>7 ");

			// 判断VO对象中生产厂商是否存在
			if (aGSManufactureVO.gs_manufacturer_name != null
					&& !aGSManufactureVO.gs_manufacturer_name.equals("")) {
				aSql.append(" or a.MANUFATURER like '%"
						+ aGSManufactureVO.gs_manufacturer_name.trim() + "%'");
			}

			// 判断VO对象中集中编码是否存在
			if (aGSManufactureVO.gs_concentricity_id != null
					&& !aGSManufactureVO.gs_concentricity_id.equals("")) {
				aSql.append(" or a.CONCENTRICITY_CODE like '%"
						+ aGSManufactureVO.gs_concentricity_id.trim() + "%'");
			}
			// 判断VO对象中产品名称是否存在
			if (aGSManufactureVO.gs_manufacture_name != null
					&& !aGSManufactureVO.gs_manufacture_name.equals("")) {
				aSql.append(" or a.NAME like '%"
						+ aGSManufactureVO.gs_manufacture_name.trim() + "%'");
			}
			// 判断VO对象中产品规格是否存在
			if (aGSManufactureVO.gs_manufacture_spec != null
					&& !aGSManufactureVO.gs_manufacture_spec.equals("")) {
				aSql.append(" or a.SPEC like '%"
						+ aGSManufactureVO.gs_manufacture_spec.trim() + "%'");
			}
			// 判断VO对象中产品型号是否存在
			if (aGSManufactureVO.gs_manufacture_type != null
					&& !aGSManufactureVO.gs_manufacture_type.equals("")) {
				aSql.append(" or a.MODEL like '%"
						+ aGSManufactureVO.gs_manufacture_type.trim() + "%'");
			}
			// 判断VO对象中产品品牌是否存在
			if (aGSManufactureVO.gs_manufacture_brand != null
					&& !aGSManufactureVO.gs_manufacture_brand.equals("")) {
				aSql.append(" or a.PRODUCT_BRAND like '%"
						+ aGSManufactureVO.gs_manufacture_brand.trim() + "%'");
			}
			// 判断VO对象中附件属性是否存在
			if (aGSManufactureVO.gs_appender_property != null
					&& !aGSManufactureVO.gs_appender_property.equals("")) {
				aSql.append(" or a.APPENDER_PROPERTY like '%"
						+ aGSManufactureVO.gs_appender_property.trim() + "%'");
			}
		} else {
			aSql.append("and (1=1 ");
		}
		aSql.append(")");
		if (aGSManufactureVO.getTmplist().size() > 0) {
			String tmp = "";
			for (int tI = 0; tI < aGSManufactureVO.getTmplist().size(); tI++) {
				GSWareHouseBean houseBean = (GSWareHouseBean) aGSManufactureVO
						.getTmplist().get(tI);
				tmp += "'" + houseBean.getCode() + "',";
			}
			aSql.append(" and a.WAREHOUSE_CODE in ("
					+ tmp.substring(0, tmp.length() - 1) + ")");
		}
		aSql.append(" order by a.CONCENTRICITY_CODE");
		return aSql.toString();
	}

	/**
	 * 产品浏览，条件查询，获得分页数量
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByData(GSManufactureVO aGSManufactureVO,String tableName)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSqlDataForProductManage(aGSManufactureVO,tableName);
		tSql = "select count(*) from(" + tSql + ")";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 产品浏览，条件查询，获得分页数量(14位临时产品)
	 * 
	 * @param aGSManufactureVO
	 * @return
	 * @throws GSException
	 */
	public int getManufactureCountByDataFor14(GSManufactureVO aGSManufactureVO)
			throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 取得查询SQL
		String tSql = this.getSqlData(aGSManufactureVO);
		tSql = "select count(*) from(" + tSql + ") ";
		try {
			return tGSManufactureDAO.queryRowNum(tSql, null);
		} catch (Exception ex) {
			GSLogWriter.error(this, ex.toString());
			throw new GSException(GSException.E19999, GSException.E19999_MSG);
		}
	}

	/**
	 * 修改产品信息记录
	 * 
	 */
	public static void modifyManufactureTask(
			GSManufactureBean aGSManufactureBean) throws GSException {
		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 修改产品信息
		if (tGSManufactureDAO.modifyManufacture(aGSManufactureBean) == false) {
			throw new GSException("修改产品信息失败!");
		}
	}

	/**
	 * 根据集中编码和产品编号查询的产品详细信息
	 */
	public GSManufactureBean getManufactureIdDetail(String tManufactureId,
			String tConcentricityId) throws GSException {
		return dao.getManufactureDetail(tManufactureId, tConcentricityId);
	}

	/**
	 * 根据送货单录入时输入的产品信息查询是否在数据库中已经存在该产品 如果产品已经存在，返回存在的产品信息，如果不存在返回空值
	 */
	public String getManufactureIdForDeliverOrder(String manufactureName,
			String spec, String type, String brand, String quantUnit,
			String price) throws GSException {
		String id = null;

		GSManufactureDAO dao = new GSManufactureDAO();
		String sql = "select * from gs_manufacture where gs_manufacture_name=? and gs_manufacture_spec=? and gs_manufacture_type=? and gs_manufacture_brand=? and gs_quant_unit=? and gs_manufacture_unitprice=?";
		Object[] cond = new Object[] { manufactureName, spec, type, brand,
				quantUnit, price };
		ArrayList ary = null;
		try {
			ary = dao.executeQuery(new GSManufactureBean(), sql, cond);
		} catch (Exception e) {
			throw new GSException(GSException.E10041, GSException.E10041_MSG);
		}
		if (ary != null && ary.size() != 0) {
			GSManufactureBean bean = (GSManufactureBean) ary.get(0);
			id = bean.getGs_manufacture_id();
		}

		return id;
	}

	public ArrayList getManufacutreByConcentricityId(String concentricityId)
			throws GSException {
		GSManufactureDAO dao = new GSManufactureDAO();
		String sql = "select * from t_product where concentricity_code=?";
		Object[] cond = new Object[] { concentricityId };
		ArrayList ary = null;
		try {
			ary = dao.executeQuery(new GSManufactureBean(), sql, cond);
		} catch (Exception e) {
			throw new GSException(GSException.E10041, GSException.E10041_MSG);
		}

		return ary;
	}

	// add by Sindy start

	// 查询前14位编码
	public ArrayList getBefore14(String ManufactureId, String IsBuy) {
		ArrayList tRs = new ArrayList();
		String tSql = "select * from gs_manufacture where substr(gs_manufacture_id,1,14)=substr(?,1,14) and gs_validity='1' and is_buy=?";
		Object[] tObj = { ManufactureId, IsBuy };
		try {
			GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
			tRs = tGSManufactureDAO.executeQuery(new GSManufactureBean(), tSql,
					tObj);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tRs;
	}

	// 查询过滤表产品编码
	public ArrayList SeachFilterId(String ManufactureId) {
		ArrayList tRs = new ArrayList();
		String tSql = "select * from gs_manufacture_filter where substr(gs_manufacture_id,1,14)=substr(?,1,14)";
		Object[] tObj = { ManufactureId };
		try {
			GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
			tRs = tGSManufactureDAO.executeQuery(new GSManufactureBean(), tSql,
					tObj);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tRs;
	}

	// 查询特约或最小价
	public ArrayList SeachManufactureValidity(String ManufactureId, String IsBuy) {
		// String mManufactureId="";
		// GSManufactureBean tGSManufactureBean = (GSManufactureBean)tList;
		// mManufactureId=tGSManufactureBean.getGs_manufacture_id();
		ArrayList tRs = new ArrayList();
		String tSql = "select * from gs_manufacture where substr(gs_manufacture_id,1,14)=substr(?,1,14) and GS_VALIDITY='1' and is_buy=? and GS_IS_TRADEFLAT_MANUFACTURE='0' order by GS_MANUFACTURE_UNITPRICE";
		Object[] tObj = { ManufactureId, IsBuy };
		try {
			GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
			tRs = tGSManufactureDAO.executeQuery(new GSManufactureBean(), tSql,
					tObj);
			if (tRs.size() == 0) {
				tSql = "select * from gs_manufacture where substr(gs_manufacture_id,1,14)=substr(?,1,14) and GS_VALIDITY='1' and is_buy=? order by GS_MANUFACTURE_UNITPRICE";
				Object[] tObj1 = { ManufactureId, IsBuy };
				tRs = tGSManufactureDAO.executeQuery(new GSManufactureBean(),
						tSql, tObj1);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tRs;

		// GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 修改产品信息
		// tGSManufactureDAO.modifyManufactureIsBuy(tGSManufactureBean);

	}

	/**
	 * 刷新指定产品的过滤表信息
	 * 
	 * @param aManufactorID
	 * @throws GSException
	 */
	public void freshFilterByManufactorID(String aManufactorID)
			throws GSException {

		GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
		// 1.更新过滤表
		if (!"".equals(aManufactorID) && aManufactorID != null) {

			// 查找产品信息
			GSManufactureBean tGSManufactureBeanOld = tGSManufactureDAO
					.getManufacture(aManufactorID);
			if (tGSManufactureBeanOld != null) {
				// 从过滤表中删除所有统一集中编码的数据
				tGSManufactureDAO.delManufactureFilterEx(tGSManufactureBeanOld
						.getGs_concentricity());

				// 2.从产品表中查出所有该集中编码的产品数据
				ArrayList tList = SeachManufactureEx(tGSManufactureBeanOld
						.getGs_concentricity());

				if (tList.size() > 0) {
					// 第一条放入fitler表
					GSManufactureBean tGSManufactureBeannew = new GSManufactureBean();
					tGSManufactureBeannew = (GSManufactureBean) tList.get(0);
					// 将最低价的产品插入过滤表
					if (tGSManufactureDAO
							.insertManufactureFilter(tGSManufactureBeannew) == false) {
						throw new GSException(GSException.E19994,
								GSException.E19994_MSG + ":插入最低价格到过滤表失败！");
					}
				}
			}
		}
	}

	// add by Sindy end

	// 查询产品表中的产品编码(特约，最小价，有效，是否采购为是)
	public ArrayList SeachManufactureEx(String ConcentricityId) {
		ArrayList tRs = new ArrayList();
		String tSql = "select * from gs_manufacture where GS_CONCENTRICITY_ID = ? and gs_validity='1' and is_buy='1' order by gs_is_tradeflat_manufacture,gs_manufacture_unitprice";
		Object[] tObj = { ConcentricityId };
		try {
			GSManufactureDAO tGSManufactureDAO = new GSManufactureDAO();
			tRs = tGSManufactureDAO.executeQuery(new GSManufactureBean(), tSql,
					tObj);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return tRs;
	}

	// add by Jackey end
	/***************************************************************************
	 * 添加产品时生成产品编号(18位）
	 * 
	 * @return
	 */
	public String getManufactureId() {
		String ver = GSSystemConfigurator.getParam("gs.Version");
		Date now = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyMMddWHHmmssSSS");// 年月日周时分秒毫秒
		return ver + formatter.format(now);
	}

	/***************************************************************************
	 * 批量导入产品生成编号
	 **************************************************************************/
	public String getManufactureId(int a) {
		String ver = GSSystemConfigurator.getParam("gs.Version");
		SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmss");
		String da = ver + formatter.format(new Date());
		String val = "";
		if (a < 10) {
			val = "000" + a;
		} else if (a < 100) {
			val = "00" + a;
		} else if (a < 1000) {
			val = "0" + a;
		} else {
			val = String.valueOf(a);
		}
		return da + val;
	}

	/** 当:修改产品集中编码时,调用此方法 */
	public boolean updateProduct(String manufacture_id, GSManufactureVO vo)
			throws GSException {
		GSManufactureDAO dao = new GSManufactureDAO();
		Connection conn = null;
		conn = dao.getConnetion();
		try {
			conn.setAutoCommit(false);
			// 修改旧记录status
			if (dao.modifyGs_validity("0", manufacture_id, conn)) {
				// 保存新记录
				if (dao.insert(vo, conn)) {
					// 修改新纪录曾用编码信息
					if (dao.saveProductOldapepcode(manufacture_id,
							vo.getGs_manufacture_id(), conn)) {
						conn.commit();
						return true;
					}
				}
			}
			conn.rollback();
		} catch (Exception e) {
			throw new GSException(e.getMessage());
		} finally {
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
			}
		}
		return false;
	}

	/** 当:修改产品集中编码时,调用此方法 */
	public boolean updateProductKM(String manufacture_id, GSManufactureVO vo)
			throws GSException {
		GSManufactureDAO dao = new GSManufactureDAO();
		Connection conn = null;
		conn = dao.getConnetion();
		try {
			conn.setAutoCommit(false);
			// 修改旧记录status
			if (dao.modifyGs_validity("0", manufacture_id, conn)) {

				// 保存新记录
				if (dao.insertForKM(vo, conn)) {
					// 修改新纪录曾用编码信息
					if (dao.saveProductOldapepcode(manufacture_id,
							vo.getGs_manufacture_id(), conn)) {
						conn.commit();
						return true;
					}
				}
			}
			conn.rollback();
		} catch (Exception e) {
			throw new GSException(e.getMessage());
		} finally {
			try {
				if (conn != null)
					conn.close();
			} catch (SQLException e) {
			}
		}
		return false;
	}

	/***************************************************************************
	 * 查询库存是否为0
	 * 
	 * @throws GSException
	 **************************************************************************/
	public String getProductCount(String id) throws GSException {
		GSManufactureDAO dao = new GSManufactureDAO();
		String tProductStorageApepBean = dao.searchProductCount(id);
		return tProductStorageApepBean;
	}

	public String appendInsertContent(GSManufactureVO vo) {
		StringBuffer buffer = new StringBuffer("产品新增。");
		buffer.append("集中编码:" + vo.getGs_concentricity_id() + ",");
		buffer.append("产品名称:" + vo.getGs_manufacture_name() + ",");
		buffer.append("型号:" + vo.getGs_manufacture_type() + ",");
		buffer.append("规格:" + vo.getGs_manufacture_spec() + ",");
		return buffer.toString();
	}
	
	
	public String appendUpdateIsBuy(GSManufactureBean bean, GSManufactureVO vo) {
		StringBuffer buffer = new StringBuffer(" ");
		buffer.append("集中编码:" + bean.getGs_concentricity() + ",");
		buffer.append("产品名称:" + bean.getGs_manufacture_name() + ",");
		buffer.append("型号:" + bean.getGs_manufacture_type() + ",");
		buffer.append("规格:" + bean.getGs_manufacture_spec() + ",");

		String isBuyStr = bean.getIs_buy().equals("1") ? "可采购" : "不可采购";
		String isBuy = vo.getIs_buy().equals("1") ? "可采购" : "不可采购";
				
		if(!vo.getIs_buy().equals(bean.getIs_buy())){
			buffer.append("原是否可采购:" +isBuyStr + ",");
			buffer.append("修改后是否可采购:" +isBuy+ ",");
		}
		
		buffer.append("最后修改人:" +vo.getLast_update_user() + ",");
		buffer.append("最后修改时间:" + vo.getLast_update_time()  + ",");
		return buffer.toString();
	}
	
	
	public String appendUpdatePrice(GSManufactureBean bean, GSManufactureVO vo) {
		StringBuffer buffer = new StringBuffer(" ");
		buffer.append("集中编码:" + bean.getGs_concentricity() + ",");
		buffer.append("产品名称:" + bean.getGs_manufacture_name() + ",");
		
		if(Double.parseDouble(vo.getGs_manufacture_unitprice())!=bean.getGs_manufacture_unitprice()&&vo.getGs_manufacture_unitprice()!=null&&!vo.getGs_manufacture_unitprice().equals("")){
			buffer.append("调价前价格:" + bean.getGs_manufacture_unitprice() + ",");
			buffer.append("调价后价格:" + vo.getGs_manufacture_unitprice() + ",");
		}
		
		String isValidityStr = bean.getGs_validity().equals("1") ? "有效" : "无效";
		String isValidity = vo.getGsValidity().equals("1") ? "有效" : "无效";
				
		if(!vo.getGsValidity().equals(bean.getGs_validity())){
			buffer.append("原是否有效:" +isValidityStr + ",");
			buffer.append("修改后是否有效:" +isValidity+ ",");
		}
		
		buffer.append("最后修改人:" +vo.getLast_update_user() + ",");
		buffer.append("最后修改时间:" + vo.getLast_update_time()  + ",");
		return buffer.toString();
	}


	public String appendUpdateContent(GSManufactureBean bean, GSManufactureVO vo) {
		int count=0;
		StringBuffer buffer = new StringBuffer(" ");
		if(!bean.getGs_concentricity().equals(vo.getGs_concentricity_id())){
			buffer.append("原集中编码:" + bean.getGs_concentricity() + ",");
			buffer.append("修改后集中编码:" + vo.getGs_concentricity_id() + ",");
			count++;
		}else{
			buffer.append("集中编码:" + bean.getGs_concentricity() + ",");
		}
		
		if(!bean.getGs_manufacture_name().equals(vo.getGs_manufacture_name())&&vo.getGs_manufacture_name()!=null&&!vo.getGs_manufacture_name().equals("")){
			buffer.append("原产品名称:" + bean.getGs_manufacture_name() + ",");
			buffer.append("修改后产品名称:" + vo.getGs_manufacture_name() + ",");
			count++;
		}else{
			buffer.append("产品名称:" + bean.getGs_manufacture_name() + ",");
		}
		
		if(!bean.getGs_manufacture_category_id().equals( vo.getGs_manufacture_category_id())&&vo.getGs_manufacture_category_id()!=null&&!vo.getGs_manufacture_category_id().equals("")){
			buffer.append("原产品分类编码:" + bean.getGs_manufacture_category_id() + ",");
			buffer.append("修改后产品分类编码:" + vo.getGs_manufacture_category_id() + ",");
			count++;
		}
		
		if(!bean.getGs_manufacture_brand().equals( vo.getGs_manufacture_brand())&& vo.getGs_manufacture_brand()!=null && ! vo.getGs_manufacture_brand().equals("")){
			buffer.append("原品牌:" + bean.getGs_manufacture_brand() + ",");
			buffer.append("修改后品牌:" + vo.getGs_manufacture_brand() + ",");
			count++;
		}
		
		if(!bean.getGs_manufacture_type().equals(vo.getGs_manufacture_type())&& vo.getGs_manufacture_type()!=null && !vo.getGs_manufacture_type().equals("") ){
			buffer.append("原型号:" + bean.getGs_manufacture_type() + ",");
			buffer.append("修改后型号:" + vo.getGs_manufacture_type() + ",");
			count++;
		}
		
		if(!bean.getGs_manufacture_spec().equals(vo.getGs_manufacture_spec())&& vo.getGs_manufacture_spec()!=null && !vo.getGs_manufacture_spec().equals("")){
			buffer.append("原规格:" + bean.getGs_manufacture_spec() + ",");
			buffer.append("修改后规格:" + vo.getGs_manufacture_spec() + ",");
			count++;
		}
		
	/*	if(!vo.getGs_manufacture_unitprice().equals(bean.getGs_manufacture_unitprice()+"")){
			buffer.append("原单价:" + getGs_manufacture_unitprice() + ",");
			buffer.append("修改后单价:" + getGs_manufacture_unitprice() + ",");
		}
		*/
		if(!bean.getGs_quant_unit().equals(vo.getGs_quant_unit())&&vo.getGs_quant_unit()!=null && !vo.getGs_quant_unit().equals("") ){
			buffer.append("原计量单位:" + bean.getGs_quant_unit() + ",");
			buffer.append("修改后计量单位:" + vo.getGs_quant_unit() + ",");
			count++;
		}
		
		if(!bean.getGs_quality_assure_period().equals(vo.getGs_quality_assure_period())&&vo.getGs_quality_assure_period()!=null&&!vo.getGs_quality_assure_period().equals("")){
			buffer.append("原质保期:" + bean.getGs_quality_assure_period() + ",");
			buffer.append("修改后质保期:" + vo.getGs_quality_assure_period() + ",");
			count++;
		}
		
		if(!bean.getGs_manufacturer_name().equals(vo.getGs_manufacturer_name())&&vo.getGs_manufacturer_name()!=null &&!vo.getGs_manufacturer_name().equals("")){
			buffer.append("原生产厂家:" + bean.getGs_manufacturer_name() + ",");
			buffer.append("修改后生产厂家:" + vo.getGs_manufacturer_name() + ",");
			count++;
		}
		
		if(!bean.getGs_make_area().equals(vo.getGs_make_area())&&vo.getGs_make_area()!=null && !vo.getGs_make_area().equals("")){
			buffer.append("原产地:" + bean.getGs_make_area() + ",");
			buffer.append("修改后产地:" + vo.getGs_make_area() + ",");
			count++;
		}
		
		if(!bean.getGs_provider_id().equals(vo.getGs_provider_id())&&vo.getGs_provider_id()!=null && !vo.getGs_provider_id().equals("")){
			buffer.append("原供应商编码:" + bean.getGs_provider_id() + ",");
			buffer.append("修改后供应商编码:" + vo.getGs_provider_id() + ",");
			count++;
		}
		
		if(!bean.getGs_adapt_machine_type().equals(vo.getGs_adapt_machine_type())&&vo.getGs_adapt_machine_type()!=null &&!vo.getGs_adapt_machine_type().equals("")&&!vo.getGs_adapt_machine_type().equals("null")){
			buffer.append("原适用机型:" + bean.getGs_adapt_machine_type() + ",");
			buffer.append("修改后适用机型:" + vo.getGs_adapt_machine_type() + ",");
			count++;
		}
		
		if(!bean.getGs_appender_property().equals(vo.getGs_appender_property())&&vo.getGs_appender_property()!=null &&!vo.getGs_appender_property().equals("")){
			buffer.append("原产品附加属性:" + bean.getGs_appender_property() + ",");
			buffer.append("修改后产品附加属性:" + vo.getGs_appender_property() + ",");
			count++;
		}
		
		if(!bean.getGs_drawing_peice_code().equals(vo.getGs_drawing_peice_code())&&vo.getGs_drawing_peice_code()!=null&&!vo.getGs_drawing_peice_code().equals("")){
			buffer.append("原图件号:" + bean.getGs_drawing_peice_code() + ",");
			buffer.append("修改后图件号:" + vo.getGs_drawing_peice_code() + ",");
			count++;
		}
		
		String balanceModeStr = bean.getGs_balance_mode().equals("1") ? "压库" : "买断";
		String isBuyStr = bean.getIs_buy().equals("1") ? "可采购" : "不可采购";
		String balanceMode = vo.getGs_balance_mode().equals("1") ? "压库" : "买断";
		String isBuy = vo.getIs_buy().equals("1") ? "可采购" : "不可采购";
		
		if(!bean.getGs_balance_mode().equals(vo.getGs_balance_mode())&&vo.getGs_balance_mode()!=null&&!vo.getGs_balance_mode().equals("")){
			buffer.append("原结算模式:" + balanceModeStr + ",");
			buffer.append("修改后结算模式:" + balanceMode+ ",");
			count++;
		}
		/*		
		if(!bean.getWarehouse_name().equals(vo.getWarehouse_name())){
			buffer.append("原仓库名称:" + bean.getWarehouse_name() + ",");
			buffer.append("修改后仓库名称:" + vo.getWarehouse_name()+ ",");
		}
		
		if(!bean.getIs_normal().equals(vo.getIs_normal())){
			buffer.append("原是否是正式产品:" + bean.getIs_normal() + ",");
			buffer.append("修改后是否是正式产品:" + vo.getIs_normal()+ ",");
		}
		
		if(!vo.getIs_buy().equals(bean.getIs_buy())){
			buffer.append("原是否可采购:" +isBuyStr + ",");
			buffer.append("修改后是否可采购:" +isBuy+ ",");
		}*/
		
		if(!bean.getKm_quality_assure_period().equals(vo.getKm_quality_assure_period())&&vo.getKm_quality_assure_period()!=null&&!vo.getKm_quality_assure_period().equals("")){
			buffer.append("原公里质保期:" + bean.getKm_quality_assure_period()  + ",");
			buffer.append("修改后公里质保期:" +vo.getKm_quality_assure_period() + ",");
			count++;
		}
		
	/*	if(!bean.getLast_update_user().equals(vo.getLast_update_user())){
			buffer.append("原最后修改人:" + bean.getLast_update_user()  + ",");
			buffer.append("修改后最后修改人:" +vo.getLast_update_user() + ",");
		}
		
		if(!bean.getLast_update_time().equals(vo.getLast_update_time())){
			buffer.append("原最后修改时间:" + bean.getLast_update_time()  + ",");
			buffer.append("修改后最后修改时间:" +vo.getLast_update_time() + ",");
		}*/
		
		if(count==0){
			return "";
		}
		
		return buffer.toString();
	}

	public String appendInputContent(String oldProductType,
			String newProductTYpe) {
		StringBuffer buffer = new StringBuffer("产品使用分类从" + oldProductType
				+ "区域转入到" + newProductTYpe + "区域");
		return buffer.toString();
	}

	public String appendExportContent(String oldProductType,
			String newProductTYpe) {
		StringBuffer buffer = new StringBuffer("产品使用分类从" + oldProductType
				+ "区域转出到" + newProductTYpe + "区域");
		return buffer.toString();
	}
}